# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

pkgbase=rhash
pkgname=("lib${pkgbase}" "lib${pkgbase}-devel" "${pkgbase}")
pkgver=1.4.1
pkgrel=1
pkgdesc='Utility for verifying hash sums of files'
url='https://sourceforge.net/projects/rhash/'
license=('custom' 'MIT')
arch=('i686' 'x86_64')
source=(${pkgbase}-${pkgver}.tar.gz::https://github.com/rhash/RHash/archive/v${pkgver}.tar.gz
        ${pkgbase}-${pkgver}.tar.gz.asc::https://github.com/rhash/RHash/releases/download/v${pkgver}/v${pkgver}.tar.gz.asc
        1.4.0_rhash-CYGWIN.patch)
makedepends=('openssl-devel')
sha256sums=('430c812733e69b78f07ce30a05db69563450e41e217ae618507a4ce2e144a297'
            'SKIP'
            'fb29ee491f6d32b3c1a4bcdef459ae84087f1e1b5ed308b382300cdc084d612f')
# https://sourceforge.net/p/rhash/wiki/PublicKey/
validpgpkeys=('2875F6B1C2D27A4F0C8AF60B2A714497E37363AE')

prepare() {
  cd RHash-${pkgver}
  patch -p2 -i ${srcdir}/1.4.0_rhash-CYGWIN.patch
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  cp -r "${srcdir}"/RHash-${pkgver} "${srcdir}"/build-${CARCH}
  cd "${srcdir}"/build-${CARCH}
  ./configure \
      --prefix=/usr \
      --sysconfdir=/etc \
      --enable-lib-static \
      --enable-lib-shared
  make
  make install DESTDIR="${srcdir}/dest" PREFIX="/usr"
}

check() {
   echo "Skipping make check"
   cd "${srcdir}"/build-${CARCH}
   make test
}

package_librhash() {
  groups=('libraries')
  pkgdesc="LibRHash shared library"
  depends=('libopenssl' 'gcc-libs')

  cd ${srcdir}/dest
  mkdir -p "${pkgdir}/usr/bin"
  cp -f usr/bin/*.dll "${pkgdir}/usr/bin"
  cd "${srcdir}"/build-${CARCH}
  # license
  install -Dm644 COPYING "${pkgdir}"/usr/share/licenses/rhash/LICENSE
}

package_librhash-devel() {
  groups=('development')
  options=('staticlibs')
  depends=("librhash=${pkgver}")
  pkgdesc="Headers and static library for LibRHash"

  cd ${srcdir}/dest
  mkdir -p ${pkgdir}/usr
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
}

package_rhash() {
  depends=("librhash=${pkgver}")
  backup=('etc/rhashrc')

  cd ${srcdir}/dest
  mkdir -p "${pkgdir}/usr/bin"
  cp -rf ${srcdir}/dest/usr/bin/* ${pkgdir}/usr/bin/
  rm  -f ${pkgdir}/usr/bin/*.dll
  cp -rf ${srcdir}/dest/usr/share/* ${pkgdir}/usr
  cp -rf ${srcdir}/dest/etc ${pkgdir}/etc
}

